<?php
/**@var \Weline\Framework\View\Template $this */
/**@var \Weline\Backend\Block\ThemeConfig $themeConfig */
$themeConfig = \Weline\Framework\Manager\ObjectManager::getInstance(\Weline\Backend\Block\ThemeConfig::class);
?>
<!DOCTYPE html>
<!--
 *@Author       秋枫雁飞
 *@Email        aiweline@qq.com
 *@Forum        https://bbs.aiweline.com
 *@DESC         后台共用头部
-->
<html lang='en' <?= ('rtl' === $themeConfig->getThemeModel()) ? " dir=\"rtl\"" : '' ?>>
<head>
    @template(Weline_Admin::common/head.phtml)
    <!-- jquery.mCustomScrollbar 插件 -->
    <link href="@static(Weline_Admin::/libs/jquery.mCustomScrollbar/jquery.mCustomScrollbar.css)" rel="stylesheet"/>
    <!-- Responsive Table css -->
    <link href='@static(Weline_Admin::assets/libs/admin-resources/rwd-table/rwd-table.min.css)' rel='stylesheet'
          type='text/css'/>
</head>

<body <?= $themeConfig->getLayouts() ?? ''; ?>>

<!--页头工具条 开始-->
@template(Weline_Admin::common/page/loading.phtml)
<!--页头工具条 结束-->

<!-- <body data-layout="horizontal" data-topbar="dark"> -->

<!-- 开始 页面 -->
<div id="layout-wrapper">


    <!--页头工具条 开始-->
    <w:block class='Weline\Admin\Block\Backend\Page\Topbar'/>
    <!--页头工具条 结束-->

    <!-- ========== Topnav Start ========== -->
    <!--页头菜单栏 开始-->
    <w:block class='Weline\Admin\Block\Backend\Page\Topnav'/>
    <!--页头菜单栏 结束-->

    <!-- ========== Left Sidebar Start ========== -->
    <!--左侧菜单栏 开始-->
    @template(Weline_Admin::common/left-sidebar.phtml)
    <!--左侧菜单栏 结束-->


    <!-- ============================================================== -->
    <!-- Start right Content here -->
    <!-- ============================================================== -->
    <div class="main-content">

        <div class='page-content'>
            <div class='container-fluid'>
                <!-- start page title -->
                <div class='row'>
                    <div class='col-12'>
                        <div class='page-title-box d-sm-flex align-items-center justify-content-between'>
                            <h4 class='mb-sm-0'>
                                <breadcrumb model="Weline\Backend\Model\Menu" order_field="order"
                                            name_field="title"></breadcrumb>
                            </h4>
                            <div class='page-title-right'>
                                <breadcrumb model='Weline\Backend\Model\Menu' order_field='order'
                                            name_field='title'></breadcrumb>
                            </div>

                        </div>
                    </div>
                </div>
                <!-- end page title -->
                <!-- start page message -->
                <div class='row'>
                    <template>Weline_Component::message.phtml</template>
                </div> <!-- end message -->
                <div class='row'>
                    <div class='col-12'>
                        <div class='card'>
                            <div class='card-body'>
                                <h4 class='card-title'>
                                    <lang>{{title}}</lang>
                                </h4>
                                <div class='table-rep-plugin'>
                                    <!-- search form -->
                                    <div class='row'>
                                        <div class='col-6'>
                                            <block class='Weline\Component\Block\Form\Search' id='queue-search'
                                                   action='*/backend/queue'
                                                   vars="req"
                                                   action-params="{module:req.module}'"
                                                   method='get' keyword='q'
                                                   value=''
                                                   placeholder='请输入关键词'></block>
                                        </div>
                                        <div class='col-6'>
                                            <div class="pull-right" style="padding: calc(32px / 2) 0;">
                                                <block class='Weline\Component\Block\OffCanvas'
                                                       template='Weline_Component::off-canvas.phtml'
                                                       title='添加队列'
                                                       cache='0'
                                                       id='create_queue_off_canvas_new'
                                                       action='*/backend/queue/form'
                                                       target-tag='button'
                                                       icon='mdi mdi-plus'
                                                       submit-button-text='保存'
                                                       submit-button-class='btn btn-primary'
                                                       target-button-text='添加'
                                                       target-button-class='btn btn-primary'
                                                       flush-button-text='刷新'
                                                       flush-button-class='btn btn -default'
                                                       flush='1'
                                                       save='0'
                                                       close-button-show='1'
                                                       close-button-text='取消'
                                                       direction='right'
                                                       class-names='w-75'
                                                       off-canvas-body-style=''
                                                />
                                            </div>
                                        </div>
                                    </div>
                                    <!-- end search form -->
                                    <div class='table-responsive mb-0' data-pattern='priority-columns'>
                                        <table id='tech-companies-1'
                                               class='table table-responsive table-striped table-bordered align-middle'>
                                            <thead>
                                            <tr>
                                                <th data-priority='1'><?= __('队列ID') ?></th>
                                                <th data-priority='1'><?= __('名称') ?></th>
                                                <th data-priority='1'><?= __('进程信息') ?></th>
                                                <th data-priority='3'><?= __('操作') ?></th>
                                                <th data-priority='3'><?= __('创建时间') ?></th>
                                                <th data-priority='3'><?= __('更新时间') ?></th>
                                            </tr>
                                            </thead>
                                            <tbody>
                                            <foreach name="queues" item="queue" key="key">
                                                <tr>
                                                    <td>
                                                        <div class="d-flex gap-1 align-items-center">
                                                            {{queue.queue_id}}
                                                            <?php
                                                            switch ($queue['status'] ?? 'error') {
                                                                case 'running':
                                                                    $status_color = 'bg-info';
                                                                    break;
                                                                case 'done':
                                                                    $status_color = 'bg-success';
                                                                    break;
                                                                case 'error':
                                                                    $status_color = 'bg-danger';
                                                                    break;
                                                                case 'stop':
                                                                    $status_color = 'bg-warning';
                                                                    break;
                                                                case 'pending':
                                                                default:
                                                                    $status_color = 'bg-secondary';
                                                                    break;
                                                            }
                                                            ?>
                                                            <span style="border-radius: 50%;width: 15px;height: 15px;display: block;"
                                                                  class='{{status_color}}'></span>
                                                            <if condition="queue.pid">
                                                                (<span><lang>进程ID:</lang>{{queue.pid}}</span>)
                                                            </if>
                                                            <if condition="queue.auto">
                                                                <i title="@lang(自动消费)"
                                                                   class="mdi mdi-brightness-auto"></i>
                                                            </if>
                                                            <if condition="queue.finished">
                                                                <i title="@lang(是否结束)"
                                                                   class="fas fa-solid fa-stop text-danger"></i>
                                                            </if>
                                                            <if condition="queue.end_at">
                                                                <i title="@lang(结束于)"
                                                                   class="mdi mdi-calendar-arrow-right">{{queue.end_at}}</i>
                                                            </if>
                                                            <block class='Weline\Component\Block\OffCanvas'
                                                                   action='queue/backend/queue/show'
                                                                   vars='queue'
                                                                   action-params='{id:queue.queue_id}'
                                                                   id='queue-show'
                                                                   target-button-text='查看'
                                                                   target-button-class=''
                                                                   title='查看队列状态'
                                                                   flush='1'
                                                                   save='0'
                                                            />
                                                        </div>
                                                    </td>
                                                    <td class='co-name' title="{{queue.name}}">
                                                        <string>queue.name|10</string>
                                                    </td>
                                                    <td class='co-name'>
                                                        <empty name='queue.result'>
                                                            <if condition="queue.status == 'pending'">
                                                                <span class="text-black-50"><lang>任务等待中...</lang></span>
                                                                <elseif condition="queue.status == 'error'"/>
                                                                <span class="text-danger"><lang>任务出错</lang></span>
                                                                <elseif condition="queue.status == 'stop'"/>
                                                                <span class="text-warning"><lang>任务已停止</lang></span>
                                                                <elseif condition="queue.status == 'done'"/>
                                                                <span class="text-success"><lang>任务已完成</lang></span>
                                                                <elseif condition="queue.status == 'running'"/>
                                                                <span class="text-info"><lang>任务正在运行...</lang></span>
                                                            </if>
                                                        </empty>
                                                        <php>
                                                            $lenght = strlen($queue['result']??'');
                                                            $show_more =( $lenght>20);
                                                        </php>
                                                        <if condition="show_more">
                                                            <string>queue.result|20</string>
                                                            <block class='Weline\Component\Block\OffCanvas'
                                                                   template='Weline_Component::off-canvas.phtml'
                                                                   cache='0'
                                                                   id='off_canvas_queue_result'
                                                                   action='*/backend/queue/detail-result'
                                                                   vars='queue'
                                                                   action-params='{id:queue.queue_id}'
                                                                   title='查看队列结果'
                                                                   close-button-show='1'
                                                                   close-button-text='关闭'
                                                                   direction='top'
                                                                   class-names='w-100 h-75'
                                                                   off-canvas-body-style=''
                                                                   target-button-text='查看全部'
                                                                   save='0'
                                                            />
                                                            <else/>
                                                            {{queue.result}}
                                                        </if>
                                                    </td>
                                                    <td class='co-name'>
                                                        <div class='d-flex gap-2'>
                                                            <if condition='queue.finished==0 and queue.status=="running"'>
                                                                <a class='text-warning'
                                                                   href="@backend-url('*/backend/queue/stop')?id={{queue.queue_id}}">
                                                                    <i class='mdi mdi-lock-reset'></i>
                                                                    <lang>暂停</lang>
                                                                </a>
                                                            </if>
                                                            <if condition='queue.finished==0 and queue.status=="error"'>
                                                                <a class='text-warning'
                                                                   href="@backend-url('*/backend/queue/continue')?id={{queue.queue_id}}">
                                                                    <i class='mdi mdi-lock-reset'></i>
                                                                    <lang>重试</lang>
                                                                </a>
                                                            </if>
                                                            <if condition='queue.status=="stop" and queue.finished==0'>
                                                                <a class='text-info'
                                                                   href="@backend-url('*/backend/queue/continue')?id={{queue.queue_id}}">
                                                                    <i class='mdi mdi-arrow-right-thin-circle-outline'></i>
                                                                    <lang>继续</lang>
                                                                </a>
                                                            </if>
                                                            <if condition='queue.finished==1'>
                                                                <a class='text-danger'
                                                                   href="@backend-url('*/backend/queue/reset')?id={{queue.queue_id}}">
                                                                    <i class='mdi mdi-lock-reset'></i>
                                                                    <lang>重新执行</lang>
                                                                </a>
                                                            </if>
                                                            <if condition='queue.finished==1 or queue.status !== "running"'>
                                                                <a class='text-danger' href="@backend-url('*/backend/queue/delete')?id={{queue
                                                                .queue_id}}">
                                                                    <i class='mdi mdi-delete'></i>
                                                                    <lang>删除</lang>
                                                                </a>
                                                            </if>
                                                            <if condition="queue.status=='pending'">
                                                                <block class='Weline\Component\Block\OffCanvas'
                                                                       template='Weline_Component::off-canvas.phtml'
                                                                       cache='0'
                                                                       id='off_canvas_queue_result'
                                                                       action='*/backend/queue/form'
                                                                       vars='queue'
                                                                       action-params='{id:queue.queue_id}'
                                                                       title='编辑队列'
                                                                       close-button-show='1'
                                                                       close-button-text='关闭'
                                                                       direction='top'
                                                                       class-names='w-100 h-75'
                                                                       off-canvas-body-style=''
                                                                       target-button-text='编辑'
                                                                       icon='mdi mdi-pencil'
                                                                       target-button-class='text-info'
                                                                       target-tag='a'
                                                                       save='0'
                                                                />
                                                            </if>
                                                        </div>
                                                    </td>
                                                    <td class='co-name'>{{queue.create_time}}</td>
                                                    <td class='co-name'>{{queue.update_time}}</td>
                                                </tr>
                                            </foreach>
                                            </tbody>
                                        </table>
                                        {{pagination}}
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div> <!-- end col -->
                </div> <!-- end row -->
            </div> <!-- container-fluid -->
        </div>
        <!-- End Page-content -->

        <footer class="footer">
            <div class="container-fluid">
                <div class="row">
                    <div class="col-sm-6">
                        <script>document.write(new Date().getFullYear())</script>
                        © Weline.
                    </div>
                    <div class="col-sm-6">
                        <div class="text-sm-end d-none d-sm-block">
                            Crafted with <i class="mdi mdi-heart text-danger"></i> By <a
                                    href="https://www.aiweline.com/">秋枫雁飞(aiweline)</a>
                        </div>
                    </div>
                </div>
            </div>
        </footer>

    </div>
    <!-- end main content-->

</div>
<!-- END layout-wrapper -->
<!--右边栏-->
@template(Weline_Admin::common/right-sidebar.phtml)

<!-- Table Editable plugin -->
<script src="@static(Weline_Admin::assets/libs/table-edits/build/table-edits.min.js)"></script>
<script src="@static(Weline_Admin::assets/js/pages/menus/table-editable.init.js)"></script>
<script src='@static(Weline_Admin::/libs/jquery.mCustomScrollbar/jquery.mCustomScrollbar.concat.min.js)'></script>
<!-- Responsive Table js -->
<script src='@static(Weline_Admin::assets/libs/admin-resources/rwd-table/rwd-table.min.js)'></script>

<!-- Init js -->
<script src='@static(Weline_Admin::assets/js/pages/table-responsive.init.js)'></script>
@template(Weline_Admin::common/footer.phtml)
</body>
</html>
